package bean;

import java.util.Set;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

public class Point extends DeepCopy<Point> {
	private static final long serialVersionUID = 5477769937972412986L;
	private int id;
	private int x;
	private int y;
	private Area area;
	private Road[] road;
	private Set<Road> roads;

	public Point() {
		super();
	}

	public Point(int id, int x, int y, Area area, Road[] rs) {
		setArea(area);
		setId(id);
		setRoad(rs);
		setX(x);
		setY(y);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Road[] getRoad() {
		return road;
	}

	public void setRoad(Road[] road) {
		this.road = road;
	}

	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Point)) {
			return false;
		}
		Point p1 = (Point) obj;
		if (this.getX() == p1.getX() && this.getY() == p1.getY()) {
			if ((this.area != null && p1.getArea() != null && this.getArea()
					.getId() != p1.getArea().getId()))
				return false;
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return this.getX() * this.getY()
				* (area == null ? super.hashCode() : area.getId());
	}

	@JSONField(serialize = false, deserialize = false)
	public Set<Road> getRoads() {
		return roads;
	}

	public void setRoads(Set<Road> roads) {
		this.roads = roads;
		if (roads != null)
			this.road = this.roads.toArray(new Road[this.roads.size()]);
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

}
